package com.student.xujiang.mysmalluse.companylogin.retrofit2protogenesis;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.student.xujiang.R;
import com.student.xujiang.mysmalluse.companylogin.model.PersonalInfo;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by xujiang on 2017/3/23.
 */

public class RecyclerViewAdapter extends RecyclerView.Adapter {


    //调用adapter的引用
    private Context context;

    private List<PersonalInfo> mData;

    //构造方法，不知道context可不可以
    public RecyclerViewAdapter(Context context, List<PersonalInfo> mData) {
        this.context = context;
        this.mData = mData;
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.item_user_recyclerview_smalluse, parent, false));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ViewHolder vh = (ViewHolder) holder;
        vh.userId.setText(mData.get(position).getUserID());
        vh.username.setText(mData.get(position).getUsername());
        vh.height.setText(mData.get(position).getHeight());
        vh.birthday.setText(mData.get(position).getBirthday());
        vh.gender.setText(mData.get(position).getGender());

    }

    @Override
    public int getItemCount() {
        return mData.size();
    }


    //需要一个内部类，继承ViewHolder
    class ViewHolder extends RecyclerView.ViewHolder {

        private View root;

        @BindView(R.id.userId)
        TextView userId;
        @BindView(R.id.username)
        TextView username;
        @BindView(R.id.height)
        TextView height;
        @BindView(R.id.birthday)
        TextView birthday;
        @BindView(R.id.gender)
        TextView gender;
        @BindView(R.id.imageView)
        ImageView imageView;


        //构造方法传入一个View作为根 有时命名为root
        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }




    }
}
